#include <bits/stdc++.h>
using namespace std;
int t,n,m,l,v;
int vd[1000010],vv[1000010],va[1000010];
int p[1000010];
bool vis[1000010];
int maxn=0;
int cnt;
vector<int> e[100010];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin >> t;
    while(t--){
        cnt=0;
        cin >> n >> m >> l >>v;
        for(int i = 1;i<=n;i++){
            cin >>vd[i]>>vv[i]>>va[i];
        }
        for(int i = 1;i<=m;i++) cin >> p[i];
        for(int i = 1;i<=n;i++){
            if(va[i]==0){
                if(vv[i]<=v) continue;
                else{
                    int f=0;
                    for(int j = 1;j<=m;j++){
                        if(p[j]>=vd[i]){
                            f++;
                            if(f==1) cnt++;
                            vis[i]=1;
                        }
                    }
                }
            }
        }
        cout << cnt<<" "<<m-1;
    }
    return 0;
}
